const express = require('express')
const path = require('path')
const fs = require('fs')
const router = express.Router()

// 获取用户菜单
router.get('/', (req, res) => {
  const tokens = (req.get('X-Token') || '').split('-')
  const len = tokens.length
  console.log(tokens, len)
  if (['admin', 'parent', 'teacher'].includes(tokens[len - 1])) {
    const menus = JSON.parse(fs.readFileSync(path.join(__dirname, `../mock/${tokens[len - 1]}.json`)) + '')
    res.json({
      code: 200,
      data: {
        menus
      }
    })
  } else {
    res.json({
      code: 4000,
      data: {
        message: 'token异常'
      }
    })
  }
})

// 退出
router.delete('/', (req, res) => {

})

module.exports = router
